<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>graphics.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_graphics_graphics.js.html">graphics.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2007 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>
<a name="line16"></a>/**
<a name="line17"></a> * @fileoverview Graphics utility functions and factory methods.
<a name="line18"></a> * @author arv@google.com (Erik Arvidsson)
<a name="line19"></a> * @see ../demos/graphics/advancedcoordinates.html
<a name="line20"></a> * @see ../demos/graphics/advancedcoordinates2.html
<a name="line21"></a> * @see ../demos/graphics/basicelements.html
<a name="line22"></a> * @see ../demos/graphics/events.html
<a name="line23"></a> * @see ../demos/graphics/modifyelements.html
<a name="line24"></a> * @see ../demos/graphics/tiger.html
<a name="line25"></a> */
<a name="line26"></a>
<a name="line27"></a>
<a name="line28"></a>goog.provide(&#39;goog.graphics&#39;);
<a name="line29"></a>
<a name="line30"></a>goog.require(&#39;goog.graphics.CanvasGraphics&#39;);
<a name="line31"></a>goog.require(&#39;goog.graphics.SvgGraphics&#39;);
<a name="line32"></a>goog.require(&#39;goog.graphics.VmlGraphics&#39;);
<a name="line33"></a>goog.require(&#39;goog.userAgent&#39;);
<a name="line34"></a>
<a name="line35"></a>
<a name="line36"></a>/**
<a name="line37"></a> * Returns an instance of goog.graphics.AbstractGraphics that knows how to draw
<a name="line38"></a> * for the current platform (A factory for the proper Graphics implementation)
<a name="line39"></a> * @param {string|number} width The width in pixels.  Strings
<a name="line40"></a> *     expressing percentages of parent with (e.g. &#39;80%&#39;) are also accepted.
<a name="line41"></a> * @param {string|number} height The height in pixels.  Strings
<a name="line42"></a> *     expressing percentages of parent with (e.g. &#39;80%&#39;) are also accepted.
<a name="line43"></a> * @param {?number=} opt_coordWidth The optional coordinate width - if
<a name="line44"></a> *     omitted or null, defaults to same as width.
<a name="line45"></a> * @param {?number=} opt_coordHeight The optional coordinate height - if
<a name="line46"></a> *     omitted or null, defaults to same as height.
<a name="line47"></a> * @param {goog.dom.DomHelper=} opt_domHelper The DOM helper object for the
<a name="line48"></a> *     document we want to render in.
<a name="line49"></a> * @return {goog.graphics.AbstractGraphics} The created instance.
<a name="line50"></a> */
<a name="line51"></a>goog.graphics.createGraphics = function(width, height, opt_coordWidth,
<a name="line52"></a>    opt_coordHeight, opt_domHelper) {
<a name="line53"></a>  var graphics;
<a name="line54"></a>  if (goog.userAgent.IE &amp;&amp; !goog.userAgent.isVersion(&#39;9&#39;)) {
<a name="line55"></a>    graphics = new goog.graphics.VmlGraphics(width, height,
<a name="line56"></a>        opt_coordWidth, opt_coordHeight, opt_domHelper);
<a name="line57"></a>  } else if (goog.userAgent.WEBKIT &amp;&amp; (!goog.userAgent.isVersion(&#39;420&#39;) ||
<a name="line58"></a>      goog.userAgent.MOBILE)) {
<a name="line59"></a>    graphics = new goog.graphics.CanvasGraphics(width, height,
<a name="line60"></a>        opt_coordWidth, opt_coordHeight, opt_domHelper);
<a name="line61"></a>  } else {
<a name="line62"></a>    graphics = new goog.graphics.SvgGraphics(width, height,
<a name="line63"></a>        opt_coordWidth, opt_coordHeight, opt_domHelper);
<a name="line64"></a>  }
<a name="line65"></a>
<a name="line66"></a>  // Create the dom now, because all drawing methods require that the
<a name="line67"></a>  // main dom element (the canvas) has been already created.
<a name="line68"></a>  graphics.createDom();
<a name="line69"></a>
<a name="line70"></a>  return graphics;
<a name="line71"></a>};
<a name="line72"></a>
<a name="line73"></a>
<a name="line74"></a>/**
<a name="line75"></a> * Returns an instance of goog.graphics.AbstractGraphics that knows how to draw
<a name="line76"></a> * for the current platform (A factory for the proper Graphics implementation)
<a name="line77"></a> * @param {string|number} width The width in pixels.  Strings
<a name="line78"></a> *     expressing percentages of parent with (e.g. &#39;80%&#39;) are also accepted.
<a name="line79"></a> * @param {string|number} height The height in pixels.   Strings
<a name="line80"></a> *     expressing percentages of parent with (e.g. &#39;80%&#39;) are also accepted.
<a name="line81"></a> * @param {?number=} opt_coordWidth The optional coordinate width, defaults to
<a name="line82"></a> *     same as width.
<a name="line83"></a> * @param {?number=} opt_coordHeight The optional coordinate height, defaults to
<a name="line84"></a> *     same as height.
<a name="line85"></a> * @param {goog.dom.DomHelper=} opt_domHelper The DOM helper object for the
<a name="line86"></a> *     document we want to render in.
<a name="line87"></a> * @return {goog.graphics.AbstractGraphics} The created instance.
<a name="line88"></a> */
<a name="line89"></a>goog.graphics.createSimpleGraphics = function(width, height,
<a name="line90"></a>    opt_coordWidth, opt_coordHeight, opt_domHelper) {
<a name="line91"></a>  if (goog.userAgent.MAC &amp;&amp; goog.userAgent.GECKO &amp;&amp;
<a name="line92"></a>      !goog.userAgent.isVersion(&#39;1.9a&#39;)) {
<a name="line93"></a>    // Canvas is 6x faster than SVG on Mac FF 2.0
<a name="line94"></a>    var graphics = new goog.graphics.CanvasGraphics(
<a name="line95"></a>        width, height, opt_coordWidth, opt_coordHeight,
<a name="line96"></a>        opt_domHelper);
<a name="line97"></a>    graphics.createDom();
<a name="line98"></a>    return graphics;
<a name="line99"></a>  }
<a name="line100"></a>
<a name="line101"></a>  // Otherwise, defer to normal graphics object creation.
<a name="line102"></a>  return goog.graphics.createGraphics(width, height, opt_coordWidth,
<a name="line103"></a>      opt_coordHeight, opt_domHelper);
<a name="line104"></a>};
<a name="line105"></a>
<a name="line106"></a>
<a name="line107"></a>/**
<a name="line108"></a> * Static function to check if the current browser has Graphics support.
<a name="line109"></a> * @return {boolean} True if the current browser has Graphics support.
<a name="line110"></a> */
<a name="line111"></a>goog.graphics.isBrowserSupported = function() {
<a name="line112"></a>  if (goog.userAgent.IE) {
<a name="line113"></a>    return goog.userAgent.isVersion(&#39;5.5&#39;);
<a name="line114"></a>  }
<a name="line115"></a>  if (goog.userAgent.GECKO) {
<a name="line116"></a>    return goog.userAgent.isVersion(&#39;1.8&#39;);
<a name="line117"></a>  }
<a name="line118"></a>  if (goog.userAgent.OPERA) {
<a name="line119"></a>    return goog.userAgent.isVersion(&#39;9.0&#39;);
<a name="line120"></a>  }
<a name="line121"></a>  if (goog.userAgent.WEBKIT) {
<a name="line122"></a>    return goog.userAgent.isVersion(&#39;412&#39;);
<a name="line123"></a>  }
<a name="line124"></a>  return false;
<a name="line125"></a>};
</pre>


</body>
</html>
